using System;
using System.Collections.Generic;
using System.Text;

namespace Mud.Common.Physical
{
    /// <summary>
    /// Represents a two-dimensional size.
    /// </summary>
    public struct Size
    {

        #region Properties

        public static readonly Size Empty = new Size(0,0);

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public int Width
        {
            get { return _width; }
            set { _width = value; }
        }
        private int _width;

        /// <summary>
        /// Gets or sets the height.
        /// </summary>
        /// <value>The height.</value>
        public int Height
        {
            get { return _height; }
            set { _height = value; }
        }
        private int _height;

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="Size"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        public Size(int width, int height)
        {
            _width = width;
            _height = height;
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="sz1">The SZ1.</param>
        /// <param name="sz2">The SZ2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(Size sz1, Size sz2)
        {
            return (sz1.Width == sz2.Width && sz1.Height == sz2.Height);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="sz1">The SZ1.</param>
        /// <param name="sz2">The SZ2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(Size sz1, Size sz2)
        {
            return !(sz1 == sz2);
        }


        /// <summary>
        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
        public bool IsEmpty {
            get { return this == Empty; }
        }

        /// <summary>
        /// Indicates whether this instance and a specified object are equal.
        /// </summary>
        /// <param name="obj">Another object to compare to.</param>
        /// <returns>
        /// true if obj and this instance are the same type and represent the same value; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            if(obj is Size) 
            {
                return (this == (Size)obj);
            }
            return false;
        }

        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>
        /// A 32-bit signed integer that is the hash code for this instance.
        /// </returns>
        public override int GetHashCode()
        {
            return (this._width ^ this._height);
        }

        /// <summary>
        /// Returns the textual representation of this instance.
        /// </summary>
        public override string ToString()
        {
            return "{Width=" + _width.ToString() + ", Height=" + _height.ToString() + "}";
        }

    }
}
